package com.lanou.dllo.shise.com.lanou.dllo.receiver;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;


import android.util.Log;

import com.lanou.dllo.shise.R;
import com.lanou.dllo.shise.com.lanou.dllo.activity.MainActivity;

public class OtherBroadcastReceiver extends BroadcastReceiver{
	private NotificationManager managerCompat; 

	@SuppressLint("ServiceCast")
	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		Log.i("lanou", "---收到广播 OtherBroadcastReceiver---");
		//获取一个NotificationManager对象
		managerCompat = (NotificationManager) 
				context.getSystemService(Context.NOTIFICATION_SERVICE);
		if(isOrderedBroadcast()) {
		String data = getResultData();
		Log.i("lanou", "----"+data);
		//收到消息之后将消息显示在通知栏中
		showNotification(context,data);
		}
		
	}
	/**在通知栏中显示一条消息**/

	private void showNotification(Context context,String data) {
		Builder builder =
				new Builder(context);
		builder.setTicker("来新消息了");
		builder.setContentTitle("有序广播");
		builder.setContentText(data);
		builder.setAutoCancel(true);
		builder.setSmallIcon(R.mipmap.ic_launcher);
		//当点击消息之后跳转到MainActivity页面
		Intent intent = new Intent(context,MainActivity.class);
		PendingIntent pi = PendingIntent.getActivity
				(context, 100, intent,PendingIntent.FLAG_UPDATE_CURRENT);
		builder.setContentIntent(pi);
		//发送消息

		managerCompat.notify(1, builder.getNotification());
	}

}
